#include "log.h"
#include "pthread.h"


 void *set_log(void *arg) {
  
  ENUM_LOG_LEVEL log_level = LOG_LEVEL_DEBUG;
  logger *set = new logger;
  cout << "before set cnt = "<<set->cnt << endl;
  set->cntplus();
  set->LogConfig();
  if(!set->OpenFile()) {
    cerr<< "fatal error!" <<endl;
    pthread_exit((void*)2);
  }

  set->SetLevel(log_level);

  if(set->IfRotateLog()) {
    set->RotateLog();
  }
  
  string msg;
  msg = "Write the Setting LOG!";
  set->log(msg);
  //set->CloseFile();  
  cout << "after set cnt = "<<set->cnt << endl;
  return((void *)0);
}

void *play_log(void *arg) {
  
  ENUM_LOG_LEVEL log_level = LOG_LEVEL_INFO;
  logger *play = new logger;
  cout << "before play cnt = "<<play->cnt << endl;
  play->cntplus();

  play->LogConfig();
  if(!play->OpenFile()) {
    cerr<< "fatal error!" <<endl;
    pthread_exit((void*)2);
  }
  
   play->SetLevel(log_level);

  if(play->IfRotateLog()) {
    play->RotateLog();
  }
   
  string msg;
  msg = "Write the Playing LOG!";
  play->log(msg);
  //play->CloseFile();

  cout << "after play cnt = "<<play->cnt << endl;
  return((void *)0);

}

void *update_log(void *arg) {
  
  ENUM_LOG_LEVEL log_level = LOG_LEVEL_ERROR;
  logger *up = new logger;
  cout << "before update cnt = "<<up->cnt << endl;
  up->cntplus();

  up->LogConfig();
  if(!up->OpenFile()) {
    cerr<< "fatal error!" <<endl;
    pthread_exit((void*)2);
  }
  
   up->SetLevel(log_level);

  if(up->IfRotateLog()) {
    up->RotateLog();
  }
   
  string msg;
  msg = "Write the updating LOG!";
  up->log(msg);
  //up->CloseFile();

  cout << "after update cnt = "<<up->cnt << endl;
  return((void *)0);

}

int main(int argc, char* argv[]) {
  pthread_t set_thread;
  pthread_t play_thread;
  pthread_t update_thread;

  pthread_create(&set_thread,NULL,set_log,NULL);
  pthread_create(&play_thread,NULL,play_log,NULL);
  pthread_create(&update_thread,NULL,update_log,NULL);


  void *result;
  pthread_join(update_thread,&result);
  pthread_join(set_thread,&result);
  pthread_join(play_thread,&result);
}
  
  
/*int main(int argc, char* argv[]){
   // LOG_FUNC_BEGIN  
  
    LOG_FUNC  
    LOG_LINE  
  
  
    int   i = 111111;  
    float f = 222.2;  
    bool  b = true;  
    enum{  
        ENUM1 = 1,  
        ENUM2,  
        ENUM3  
    };  
    CLog::WriteLog("abcd1234……");  
   // CLog::WriteLog(i);  
   // CLog::WriteLog(f);  
   // CLog::WriteLog(b);  
   //CLog::WriteLog(ENUM1);  
  
  
   // LOG_FUNC_END  
  
    return true;  // 除非将焦点设置到控件，否则返回 TRUE  
}*/
